home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 147
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin
/
tools
/
zmc3v078
/
zmc3v078.lzh
/
SRCSV078.LZH
/
MAKEZMD1.C
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-01
|
73KB
|
2,764 lines
/* ==================================
ZMS->ZMD common track compile
================================== */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include "switch.h"
#include "parsesub.h"
#include "makezmd.h"
#include "etc.h"
#include "68lib.h"
#include "structs.h"
#include "structs2.h"
enum {
#define ZMSCOMMAND(c,s) c,
#include "zmscmd.h"
#include "cmncmd.h"
#undef ZMSCOMMAND
dummy /* it's needed for BCB */
};
UBYTE *makeZmdMeter(UBYTE *zms,COMMONINF *cominf,
TRKCHINF *trkdata, const BYTE target[]);
UBYTE *makeZmdKey(UBYTE *zms,COMMONINF *cominf,
TRKCHINF *trkdata, const BYTE target[]);
UBYTE *makeZmdKey0(UBYTE *zms,int var[]);
UBYTE *makeZmdSc88ModeSet(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[]);
UBYTE *makeZmdXgPrint(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[]);
UBYTE *makeZmdMu100VoiceMap(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[]);
UBYTE *makeZmdMu100VoiceMapMain(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],const int mode);
UBYTE *makeZmdGsXgDisplay(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf, const BYTE target[], int mode);
UBYTE *makeZmdGmSystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
const BYTE target[]);
UBYTE *makeZmdGm2SystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
const BYTE target[]);
UBYTE *makeZmdXgSystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
const BYTE target[]);
TRKCHINF *makeZmdCommon(TRKCHINF *trkdata,UBYTE *zms, UBYTE **zms2,
COMMONINF *cominf, const int mode);
UBYTE *makeZmdGatetimeResolution(UBYTE *zms,COMMONINF *cominf,
TRKINF *trkinf, const BYTE target[]);
UBYTE *macroExclusive0(UBYTE *zms, BYTE e[], const DWORD elen,
const char *cmnt,
int idflag, int roland, TRKCHINF *trkdata,
const BYTE target[]);
UBYTE *macroExclusiveN(UBYTE *zms, BYTE e[], const DWORD elen,const DWORD zmdlen,
const char *cmnt,
int idflag,int roland, const UBYTE mdl,const int warnlvl,
UBYTE *warn, TRKCHINF *trkdata);
UBYTE *getDevice(UBYTE *zms, DWORD *ch, DWORD *chtype, COMMONINF *cominf,
int allowALL);
UBYTE *setTempo(UBYTE *zms, char *endchar,COMMONINF *cominf);
UBYTE *initializeZMD(UBYTE *zms, TRKCHINF *trkdata, const char *endchar);
UBYTE *setMasterClock(UBYTE *zms, const char *endchar, COMMONINF *cominf);
UBYTE *getIfnoAndComment(UBYTE *zms, const char *endchar,
DWORD *ifno, char **cmnt);
UBYTE *getAssign2(UBYTE *zms, TRKCHINF *trkdata,const int trk, const char *endchar);
UBYTE *makeZmdAssign(UBYTE *zms,TRKCHINF *trkdata,
COMMONINF *cominf, BYTE *trks, const int mode);
void makeZmdAssignMain(TRKCHINF *trkdata,COMMONINF *cominf,
int trk, BYTE *trks, int ch, int chtype);
UBYTE *makeZmdPlaytrk(UBYTE *zms, TRKCHINF *trkdata,
int *stat, UBYTE **playtrk_start, int mode);
extern DWORD line;
extern char *linebuf;
extern LINEDATA *ld;
/* (BEGIN FM/ADPCMsupport by Mamiya */
typedef struct {
WORD note;
WORD pitchpara;
WORD volumepara;
WORD mixdelay;
WORD mixnote;
WORD cutofs;
WORD cutsize;
BYTE revsw;
WORD fadeofs;
BYTE fadedir;
BYTE fadelevel;
WORD srcnote;
} REGISTER_PCM;
#ifdef A
UBYTE *makeZmdCommonRegPcm(UBYTE *zms,TRKCHINF *trkdata,DWORD note, DWORD bank)
{
const REGISTER_PCM initreg = {
0, -333, -333, 0,-1, 0,0, 0, 0,0,0 ,-333
};
DWORD tmpDWORD;
UBYTE *strstart;
int err, srclen;
REGISTER_PCM *rp;
rp = emalloc(sizeof(REGISTER_PCM),"rp");
*rp = initreg; /* memcpy(rp, initreg, sizeof(REGISTER_PCM)); */
rp->note = note;
if (bank) rp->note += bank << 7;
zms = skipSpc(zms);
if (*zms == '=') zms = skipSpc(zms + 1);
if (('0' <= *zms && *zms <= '9') || *zms == '$' || *zms == '%') {
zms = getnum2(zms, &tmpDWORD, &err);
rp->srcnote = tmpDWORD;
srclen = 0;
} else if (*zms == '\"' || *zms == '\'') {
UBYTE endc;
endc = *zms++;
strstart = zms;
while (*zms >= ' ' && *zms != endc && *zms != 0xff) zms++;
srclen = zms - strstart;
if (*zms == endc) zms++;
} else {
strstart = zms;
while (*zms > ' ' && *zms != ',' && *zms != '/' && *zms != 0xff) zms++;
srclen = zms - strstart;
}
zms = skipSpc(zms);
while (1) {
if (*zms == ',') zms = skipSpc(zms + 1);
switch (*zms) {
case 'p': case 'P':
zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
rp->pitchpara = tmpDWORD + 12;
if (rp->volumepara == -333) rp->volumepara = 100;
continue;
case 'v': case 'V':
zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
rp->volumepara = tmpDWORD;
if (rp->pitchpara == -333) rp->pitchpara = 12;
continue;
case 'm': case 'M':
zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
rp->mixnote = tmpDWORD;
/* if (bank) rp->mixnote += bank << 7; */
if (*zms == ',') {
zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
rp->mixdelay = tmpDWORD;
}
continue;
case 'c': case 'C':
zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
rp->cutofs = tmpDWORD;
if (*zms == ',') {
zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
rp->cutsize = tmpDWORD;
}
continue;
case 'r': case 'R':
rp->revsw = -1;
zms++;
continue;
case 'f': case 'F':
zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
if (tmpDWORD < 0) {
rp->fadeofs = -tmpDWORD;
rp->fadedir = -1;
} else {
rp->fadeofs = tmpDWORD;
rp->fadedir = 1;
}
if (*zms == ',') {
zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
rp->fadelevel = tmpDWORD;
}
continue;
default:
break;
}
break;
}
if (rp->pitchpara == -333) rp->pitchpara = 0;
if (rp->volumepara == -333) rp->volumepara = 0;
*trkdata[0].zmd++ = 0x40;
putWord(trkdata[0].zmd, rp->note);
trkdata[0].zmd += 2;
putWord(trkdata[0].zmd, rp->pitchpara);
trkdata[0].zmd += 2;
putWord(trkdata[0].zmd, rp->volumepara);
trkdata[0].zmd += 2;
putWord(trkdata[0].zmd, rp->mixdelay);
trkdata[0].zmd += 2;
putWord(trkdata[0].zmd, rp->mixnote);
trkdata[0].zmd += 2;
putWord(trkdata[0].zmd, rp->cutofs);
trkdata[0].zmd += 2;
putWord(trkdata[0].zmd, rp->cutsize);
trkdata[0].zmd += 2;
*trkdata[0].zmd++ = rp->revsw;
putWord(trkdata[0].zmd, rp->fadeofs);
trkdata[0].zmd += 2;
*trkdata[0].zmd++ = rp->fadedir;
*trkdata[0].zmd++ = rp->fadelevel;
if (rp->srcnote != -333) {
putWord(trkdata[0].zmd, 0);
trkdata[0].zmd += 2;
putWord(trkdata[0].zmd, rp->srcnote);
trkdata[0].zmd += 2;
} else {
int i;
for (i = 0; i < srclen; i++) *trkdata[0].zmd++ = strstart[i];
*trkdata[0].zmd++ = 0;
}
efree(rp,"rp");
return zms;
}
/* FM/ADPCMsupport by Mamiya END) */
#endif
UBYTE *makeZmdGatetimeResolution(UBYTE *zms,COMMONINF *cominf,
TRKINF *trkinf, const BYTE target[])
{
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
DWORD var;
int err;
zms = getnum2(zms,&var,&err);
if (err) {
zmserror(".gatetime_resolution must be followed to its parameter.",line,linebuf,zms,0,1);
} else if (var < 1) {
zmserror(".gatetime_resolution parameter is out of range(8-128).",line,linebuf,zms,0,1);
}
switch (var) {
case 8: case 16: case 32: case 64: case 128:
break;
default:
zmserror(".gatetime_resolution parameter is out of range(8,16,32,64,128).",line,linebuf,zms,4,1);
break;
}
if (target[trk] == 0) {
cominf->gtreso = var;
} else {
trkinf[target[trk]].gtreso = var;
}
}
return zms;
}
UBYTE *makeZmdMeter(UBYTE *zms,COMMONINF *cominf,
TRKCHINF *trkdata, const BYTE target[])
{
int trk;
UBYTE *zms_ = zms;
for (trk = 0; target[trk] >= 0; trk++) {
DWORD m, n;
int err;
zms = getnum2(zms_, &m, &err);
/* zms = skipSpc(zms); */ /* can't use skipSpc because it skips '/' */
while (isspace(*zms)) {
zms++;
}
if (*zms++ != '/') {
zmserror("METER: illegal format. ( METER m/n )",line,linebuf,zms,0,1);
}
zms = getnum2(zms, &n, &err);
if (target[trk] == 0) {
cominf->meter = m * 256 + n;
} else {
*trkdata[target[trk]].zmd++ = 0xC5;
*trkdata[target[trk]].zmd++ = 0x05;
*trkdata[target[trk]].zmd++ = 0x02;
*trkdata[target[trk]].zmd++ = m;
*trkdata[target[trk]].zmd++ = n;
}
}
return zms;
}
UBYTE *makeZmdKey(UBYTE *zms,COMMONINF *cominf,
TRKCHINF *trkdata, const BYTE target[])
{
int trk;
int var[2] = { 0, 0 };
zms = makeZmdKey0(zms, var);
for (trk = 0; target[trk] >= 0; trk++) {
if (target[trk] == 0) {
cominf->key = var[0];
cominf->majorflag = var[1];
} else {
*trkdata[target[trk]].zmd++ = 0xC5;
*trkdata[target[trk]].zmd++ = 0x04;
*trkdata[target[trk]].zmd++ = 0x02;
*trkdata[target[trk]].zmd++ = var[0];
*trkdata[target[trk]].zmd++ = var[1];
}
}
return zms;
}
UBYTE *makeZmdKey0(UBYTE *zms,int var[])
/* var[0] == # of #/b
* var[1] == major[0] / minor[1] / error[-1]
*/
{
int m = 0, n = 0;
int bracket = 0;
int flg = 1;
zms = skipSpc(zms);
if (*zms == '{') {
bracket = 1;
zms++;
}
do {
int i;
const char *cho="fcgdaeb-+#m";
for (i = 0; i < (int)strlen(cho); i++) {
if (tolower(*zms) == cho[i]) {
zms++;
break;
}
}
switch (i) {
case 7: /* - */
m -= 7;
break;
case 8: /* # */
case 9: /* + */
m += 7;
break;
case 10: /* m */
flg = -1;
break;
case 11: /* no found */
if (!isspace(*zms) && *zms != '/' &&
*zms != 0x0D && *zms != 0x0A) {
n = -1;
}
flg = 0;
break;
default: /* FCGDAEB */
m = i - 1;
break;
}
} while (flg > 0);
if (!stricmp2(zms,"ajor")) {
zms += 4;
} else if (!stricmp2(zms,"inor") || flg < 0) {
m -= 3;
n = 1;
if (!stricmp2(zms,"inor")) {
zms += 4;
}
}
zms = skipSpc(zms);
if (bracket) {
if (*zms != '}') {
zmserror("KEY: format error.",line,linebuf,zms,0,1);
} else {
zms++;
}
}
var[0] = m;
var[1] = n;
return zms;
}
UBYTE *makeZmdSc88ModeSet(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[])
/* 41 id 42 12 00 00 7f xx */
{
int trk;
UBYTE *zms_ = zms;
for (trk = 0; target[trk] >= 0; trk++) {
DWORD mode,id,ifno;
int err;
const int elen = 9;
BYTE e[9] = { 0xf0,0x41,0x10,0x42,0x12,0x00,0x00,0x7f,0x00 };
const int Trk = target[trk];
const char *p[] = {"single", "double",NULL};
zms = getnum4(zms_,&mode,&err, p, 1);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (mode < 1 && 2 < mode) {
zmserror(".SC88_MODE: the mode is out of range.",line,linebuf,zms,0,1);
}
e[8] = mode - 1;
zms = skipchr(zms,", \t\x0d\x0a");
zms = getnum2(zms,&id,&err);
if (err < 0) {
id = 0x10;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (id < 0) {
/* It is not to be error in V2, but.... */
}
e[2] = id;
if (Trk == 0) { /* common trk */
zms = skipchr(zms,", \t\x0d\x0a");
zms = getnum2(zms,&ifno,&err);
if (err < 0) {
ifno = 0xFF;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (ifno < 0) {
/* It is not to be error in V2, but.... */
}
}
*trkdata[Trk].zmd++ = (Trk)? 0xF3 : 0x34;
*trkdata[Trk].zmd++ = (Trk)? 0x41 : ifno;
*trkdata[Trk].zmd ++ = strlen("SC88_MODE");
strncpy(trkdata[Trk].zmd, "SC88_MODE", strlen("SC88_MODE"));
trkdata[Trk].zmd += strlen("SC88_MODE");
if (Trk) {
putDword(trkdata[Trk].zmd, 4);
trkdata[Trk].zmd += 4;
memcpy(trkdata[Trk].zmd, &e[5], elen - 5);
trkdata[Trk].zmd += elen - 5;
} else {
putDword(trkdata[Trk].zmd, (elen + 2) ); /* +2: checksum,0xf7 */
trkdata[Trk].zmd += 4;
trkdata[Trk].zmd = setex(trkdata[Trk].zmd, e, elen, 1);
*trkdata[Trk].zmd++ = 0xf7;
}
}
return zms;
}
UBYTE *makeZmdXgPrint(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[])
/* .XG_PRINT id,if str */
/* $F0,$43,id,$4C,$06,$00,$00,文字列(ASCIIコード、32文字まで) ~,$F7 */
{
DWORD dev, ifno = -1;
int err;
const int f0f7 = 1,roland = 3; /* YAMAHA without checksum */
const UBYTE mdl = 0x4C;
int elen = 3;
UBYTE e[3] = {0x06,0x00,0x00};
DWORD zmsskip;
zms = getnum2(zms,&dev,&err);
if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (err < 0) {
dev = 0x10;
}
zms = skipSpc(zms);
if (*zms == ',') {
zms = getnum2(++zms, &ifno,&err);
if (err < 0) {
ifno = -1;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (ifno < 0) {
/* It is not to be error in V2 */
}
}
trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,
f0f7, &zmsskip,
ifno, "XG_PRINT",
roland,dev,mdl,
elen,e,
"\"","\"\x0d\x0a");
/*
if (trkdata[0].zmd - ex_b0 > 3+5+3+32+1) {
zmserror("it must be under 32 characters in .xg_print.",line,linebuf,zms,2,1);
}
*/
zms += zmsskip;
/* cominf->z_cmn_flag |= (1 << (0x34 / 4)); */
return zms;
}
UBYTE *makeZmdMu100VoiceMap(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[])
{
int err;
const char *p[] = {"basic", "native",NULL};
DWORD mode;
zms = getnum4(zms,&mode,&err, p, 0);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (mode < 0 && 1 < mode) {
zmserror(".MU100_VOICE_MAP: the mode is out of range.",line,linebuf,zms,0,1);
}
return makeZmdMu100VoiceMapMain(zms,trkdata,target,mode);
}
UBYTE *makeZmdMu100VoiceMapMain(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],const int mode)
{
/* .MU100_VOICE_MAP map,id,if */
/* $F0,$43,id,$49,$00,$00,$12,map,$F7 */
int elen = 8;
BYTE e[8] = { 0xf0,0x43,0x10,0x49,0x00,0x00,0x12,0x00 };
const int rolandchecksum = 0, idflag = 1;
e[7] = mode;
zms = macroExclusive0(zms, e, elen,
"MU100_VOICE_MAP",
idflag,rolandchecksum, trkdata, target);
return zms;
}
UBYTE *makeZmdGsXgDisplay(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf, const BYTE target[], int mode)
/* mode: 0=GS, 1=XG */
{
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
DWORD dev,ifno = -1;
int err, j;
/* DWORD zmsskip;
*/ char *cmnt = NULL;
int c = 0;
int elen;
UBYTE e[2][8 + 64];
const UBYTE e0[8] = {0xF0,0x41,0x10,0x45,0x12,0x10,0x01,0x00};
const UBYTE e1[7] = {0xF0,0x43,0x10,0x4C,0x07,0x00,0x00};
/*initialize; header part only */
UWORD buf[16]; /*, ebuf[64];*/
memcpy(&e[0][0],e0,8);
memcpy(&e[1][0],e1,7);
zms = getnum2(zms,&dev,&err);
if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (err < 0) {
dev = 0x10;
}
e[mode][2] = dev;
zms = skipSpc(zms);
if (*zms == ',') {
zms++;
}
zms = getIfnoAndComment(zms, "{",&ifno, &cmnt);
zms++; /* { */
while (*zms != '}') { /* Too weak the error check is! */
DWORD tmpDWORD;
zms = getnum2(zms,&tmpDWORD,&err);
if (!err) {
if (c > 15) {
zmserror("too many parameters.",line,linebuf,zms,0,1);
}
buf[c++] = tmpDWORD;
}
zms = skipSpcCr(zms);
if (*zms == ',') {
zms++;
} else if (*zms == '/') {
zms = skipComment(zms);
}
}
zms++;
if (c != 16) {
zmserror("too few parameters.",line,linebuf,zms,0,1);
}
if (mode == 0) { /* GS */
int i;
elen = 8;
for (i = 3; i >= 0; i--) {
int j;
for (j = 0; j < 16; j++) {
e[mode][i * 16 + j + elen] =
(i == 3)? ((buf[j] & 1) << 4) : (buf[j] & 31);
buf[j] >>= (i == 3)? 1 : 5;
}
}
elen += 64;
} else { /* XG */
int i;
elen = 7;
for (i = 2; i >= 0; i--) {
int j;
for (j = 0; j < 16; j++) {
if (i != 2) {
e[mode][i * 16 + j + elen] =
(buf[j] >> (-(i * 7) + 9) & 0x7F);
} else {
e[mode][i * 16 + j + elen] =
(buf[j] << ((2 * 7) - 9) & 0x7F);
}
}
}
elen += 48;
}
*trkdata[0].zmd++ = 0x34;
*trkdata[0].zmd++ = ifno; /* IF number: (-1 == current IF) */
if (cmnt) {
*trkdata[0].zmd++ = strlen(cmnt); /* comment length */
strcpy(trkdata[0].zmd, cmnt);
trkdata[0].zmd += strlen(cmnt);
} else {
*trkdata[0].zmd++ = 0;
}
putDword(trkdata[0].zmd, elen + 2 - mode); /* +2: checksum,0xf7 */
trkdata[0].zmd += 4;
trkdata[0].zmd = setex(trkdata[0].zmd, &e[mode][0], elen, 1 - mode);
*trkdata[0].zmd++ = 0xf7;
cominf->z_cmn_flag |= (1 << (0x34 / 4));
if (cmnt) {
efree(cmnt,"cmnt");
}
}
return zms;
}
UBYTE *makeZmdGmSystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
const BYTE target[])
{
/* 18 00 06 F0 7E 7F 09 01 F7 */
const DWORD elen = 5;
BYTE e[5] = { 0xf0,0x7e,0x7f,0x09,0x01 };
const int rolandchecksum = 0;
const int idflag = 0;
zms = macroExclusive0(zms, e, elen,
"GM_SYSTEM_ON",
idflag,rolandchecksum, trkdata, target);
return zms;
}
UBYTE *makeZmdGm2SystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
const BYTE target[])
{
/* 18 00 06 F0 7E 7F 09 02 F7 */
const DWORD elen = 5;
BYTE e[5] = { 0xf0,0x7e,0x7f,0x09,0x02 };
const int rolandchecksum = 0;
const int idflag = 0;
zms = macroExclusive0(zms, e, elen,
"GM2_SYSTEM_ON",
idflag,rolandchecksum, trkdata, target);
zmserror(".gm2_system_on can use only for zmc3.",line,linebuf,zms,4,1);
return zms;
}
UBYTE *makeZmdXgSystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
const BYTE target[])
{
const DWORD elen = 8;
BYTE e[8] = { 0xf0,0x43, 0x10, 0x4c,
0x00,0x00,0x7e,0x00 };
const int rolandchecksum = 0;
const int idflag = 1;
zms = macroExclusive0(zms, e, elen,
"XG_SYSTEM_ON",
idflag,rolandchecksum, trkdata, target);
zmserror(".xg_system_on can use only for zmc2.",line,linebuf,zms,4,1);
return zms;
}
TRKCHINF *makeZmdCommon(TRKCHINF *trkdata,UBYTE *zms, UBYTE **zms2,
COMMONINF *cominf, const int mode)
{
/* UBYTE *zmsbuf = zms; */
UBYTE *playtrk_start = NULL;
int stat = 0;
BYTE trks = 0;
/* (BEGIN FM/ADPCMsupport by Mamiya */
const char default_fmtone[55] = {
0,0,0,0,0, 0,0,0,0,0, 0,
0,0,0,0,0, 0,0,0,0,0, 0,
0,0,0,0,0, 0,0,0,0,0, 0,
0,0,0,0,0, 0,0,0,0,0, 0,
0,0,15,3,0,0,0,0,0,0, 0,
};
memcpy(cominf->opmtone, default_fmtone, 55);
cominf->fmvol = 255;
cominf->adpcmbank = 0;
cominf->polpcm = 0;
/* FM/ADPCMsupport by Mamiya END) */
/* linebuf = zms;*/
/*
strncpy(trkdata[0].zmd,"\x10ZmuSiC\x20",8);
trkdata[0].zmd += 8;
*/
while (!stat) {
const DWORD bs = trkdata[0].zmd - trkdata[0].zmdbuf;
if (bs > trkdata[0].bufsize - MTRK_OVERFLOW_RANGE) {
trkdata[0].bufsize += FIRST_MTRK_SIZE;
trkdata[0].zmdbuf = (UBYTE*)erealloc(trkdata[0].zmdbuf,sizeof(UBYTE) * trkdata[0].bufsize,"trkdata[0].zmdbuf");
trkdata[0].zmd = trkdata[0].zmdbuf + bs;
}
zms = skipSpcCr(zms);
#ifdef A
/* (BEGIN FM/ADPCMsupport by Mamiya */
{
DWORD note;
int err;
zms = getnum2(zms, ¬e, &err);
if (!err) {
zms = makeZmdCommonRegPcm(zms, trkdata, note, 0);
continue;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
}
/* FM/ADPCMsupport by Mamiya END) */
#endif
/*fprintf(stderr,"(loop start)\n");*/
switch(*zms++) {
int i;
case 0xFF: /* EOF */
stat = -1;
*trkdata[0].zmd++ = 0xFF;
if ((trkdata[0].zmd - trkdata[0].zmdbuf) & 1) {
*trkdata[0].zmd++ = 0xFF;
}
break;
case '/':
zms = skipComment(zms);
break;
case '.':
{
const struct {
int zmscmdcode;
char *zmscmd;
} comtbl1[] = {
#define ZMSCOMMAND(c,s) {c, s},
#include "zmscmd.h"
#include "cmncmd.h"
#undef ZMSCOMMAND
{-1, NULL},
};
for (i = 0;;i++) {
if (!comtbl1[i].zmscmd) break;
if (!stricmp2(zms,comtbl1[i].zmscmd)) {
zms += strlen(comtbl1[i].zmscmd);
break;
}
}
i = comtbl1[i].zmscmdcode;
}
switch (i) {
/*
ZMSCOMMAND(ZMSCMD_SC88_USER_INST,"SC88_USER_INST")
ZMSCOMMAND(ZMSCMD_SC88_USER_DRUM,"SC88_USER_DRUM")
ZMSCOMMAND(ZMSCMD_SC88_DRUM_NAME,"SC88_DRUM_NAME")
*/
/*OK*/ case ZMSCMD_SC88_MODE_SET: /* ,sc88_mode_set (V3 extention) */
/*OK*/ case ZMSCMD_SC88_MODE:
{
const BYTE target[] = {0, -1};
zms = makeZmdSc88ModeSet(zms, trkdata, target);
cominf->z_cmn_flag |= (1 << (0x34 / 4));
}
break;
case ZMSCMD_MU100_BASIC_MAP: /* .mu100_basic_map (zmc2 extention) */
/*OK*/ case ZMSCMD_MU100_NATIVE_MAP: /* .mu100_native_map (zmc2 extention) */
{
int mode = 0;
const BYTE target[] = {0, -1};
if (i == ZMSCMD_MU100_NATIVE_MAP) {
mode = 0x01;
zmserror(".mu100_native_map can use only for zmc2.",line,linebuf,zms,4,1);
} else {
zmserror(".mu100_basic_map can use only for zmc2.",line,linebuf,zms,4,1);
}
zms = makeZmdMu100VoiceMapMain(zms,trkdata,target,mode);
cominf->z_cmn_flag |= (1 << (0x34 / 4));
}
break;
/*OK*/ case ZMSCMD_MU100_VOICE_MAP: /* .mu100_voice_map (zmc3 extention) */
{
const BYTE target[] = {0, -1};
zms = makeZmdMu100VoiceMap(zms,trkdata,target);
cominf->z_cmn_flag |= (1 << (0x34 / 4));
}
break;
case ZMSCMD_GATETIME_RESOLUTION:
{
const BYTE target[] = {0, -1};
zms = makeZmdGatetimeResolution(zms, cominf, (TRKINF*)NULL, target);
}
break;
case ZMSCMD_METER:
{
const BYTE target[] = {0, -1};
zms = makeZmdMeter(zms, cominf, trkdata, target);
}
break;
case ZMSCMD_KEY:
{
const BYTE target[] = {0, -1};
zms = makeZmdKey(zms, cominf, trkdata, target);
}
break;
case ZMSCMD_INCLUDE:
{
#ifdef AAA
int bnest = 0;
while (*zms != 0xFF) {
if (*zms == '{') {
bnest++;
} else if (*zms == '}') {
bnest--;
if (bnest <= 0) {
zms++;
break;
}
} /* macro expansion is already done */
zms++;
}
#endif
zms = skipSpc(zms);
while (isgraph(*zms) && *zms != '/') {
zms++;
}
/* fprintf(stderr,"[include ned]"); */
}
break;
case ZMSCMD_CURRENT_MIDI_OUT:
{
DWORD ifno;
int err;
zms = getnum2(zms,&ifno,&err);
if (err) {
zmserror("no IF number is specified.",line,linebuf,zms,0,1);
} else if (ifno < 1 || 4 < ifno) {
zmserror("IF number must be within the range 1-4.",line,linebuf,zms,0,1);
}
*trkdata[0].zmd++ = 0x30;
*trkdata[0].zmd++ = ifno - 1;
cominf->currentmidiout = ifno;
cominf->z_cmn_flag |= (1 << (0x30 / 4));
}
break;
/*OK*/ case ZMSCMD_ASSIGN: /* .assign */
{
zms = makeZmdAssign(zms,trkdata,cominf,&trks,0);
#ifdef A
DWORD trk, ch, chtype;
int i, err;
zms = skipSpc(zms);
if (!stricmp2(zms,"tr")) {
zms += 2;
}
zms = getnum2(zms,&trk,&err);
if (err) {
zmserror("no track number is specified.",line,linebuf,zms,0,1);
} else if (trk <= 0) {
zmserror("illegal track number is specified.",line,linebuf,zms,0,1);
}
for (i = 0; i < trks; i++) {
if (cominf->trkassign[i] == trk) {
zmserror("The specified track# is already used.",line,linebuf,zms,0,1);
}
}
zms = skipSpcCr(zms);
if (*zms == '{' || *zms == ',') {
zms++;
}
zms = getDevice(zms,&ch, &chtype, cominf, 0);
/*
zms = skiptochr(zms,"}");
zms++;
*/
trkdata[trk].ch = trkdata[trk].ch_ = ch;
trkdata[trk].chtype = chtype;
cominf->trkassign[trks++] = trk;
cominf->trkassign[trks] = -1;
/* fprintf(stderr,"[%d,%d]",trk,ch); */
zms = getAssign2(zms, trkdata, trk, "}");
#endif
}
break;
/*OK*/ case ZMSCMD_TEMPO: /* .tempo (V3 extention) */
zms = setTempo(zms, NULL, cominf);
/*
zmserror(".tempo can use only on V3.",line,linebuf,zms,3,1);
*/
/* cominf->z_cmn_flag |= (1 << (0x08 / 4)); */
break;
/*OK*/ case ZMSCMD_INITIALIZE: /* .initialize */
zms = initializeZMD(zms, trkdata, NULL);
/*
zmserror(".initialize can use only on V3.",line,linebuf,zms,3,1);
*/
cominf->z_cmn_flag |= (1 << (0x00 / 4));
break;
/*OK*/ case ZMSCMD_MASTER_CLOCK: /* .master_clock (V3 extention) */
zms = setMasterClock(zms, NULL, cominf);
/*
zmserror(".master_clock can use only on V3.",line,linebuf,zms,3,1);
*/
break;
/*OK*/ case ZMSCMD_YAMAHA_EXCLUSIVE:
/*OK*/ case ZMSCMD_XG_EXCLUSIVE:
case ZMSCMD_DX_BULK_DUMP:
{
const UBYTE f0f7 = 1;
UBYTE roland = 2;
DWORD dev,mdl,ifno = -1;
int err;
DWORD zmsskip;
char *cmnt = NULL;
if (i == ZMSCMD_DX_BULK_DUMP) {
roland = 4;
} else if (i == ZMSCMD_XG_EXCLUSIVE) {
mdl = 0x4C;
roland = 3;
} else if (ZMSCMD_YAMAHA_EXCLUSIVE) {
mdl = 0x43;
roland = 2;
}
zms = getnum2(zms,&dev,&err);
if (err < 0) {
dev = 0x10;
/* mdl = 0x16; */ /* default:MT-32? */
}
zms = skipSpcCr(zms);
if (i != ZMSCMD_XG_EXCLUSIVE) {
/* if (i != ZMSCMD_XG_EXCLUSIVE && strchr(", \t",*zms)) { */
zms = getnum2(zms,&mdl,&err);
}
zms = skipSpcCr(zms);
if (*zms == ',') {
zms++;
}
zms = getIfnoAndComment(zms, "{",&ifno, &cmnt);
trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,
f0f7, &zmsskip,
ifno,cmnt,roland,dev,mdl,
0,"",
"{","}, \t\x0d\x0a");
cominf->z_cmn_flag |= (1 << (0x34 / 4));
zms += zmsskip;
if (cmnt) {
efree(cmnt,"cmnt");
}
/*
zmserror(".yamaha_exclusive can use only on V3.",line,linebuf,zms,3,1);
*/
}
break;
case ZMSCMD_XG_EQUALIZER:
{
DWORD dev,ifno = -1;
int err, j;
DWORD zmsskip;
char *cmnt = NULL;
zms = getnum2(zms,&dev,&err);
if (err < 0) {
dev = 0x10;
}
zms = skipSpc(zms);
if (*zms == ',') {
zms++;
}
zms = getIfnoAndComment(zms, "{",&ifno, &cmnt);
zms++; /* { */
for (j = 0; j < 6; j++) {
int elen = 8;
BYTE e[8] = { 0xf0,0x43,0x10,0x4C,0x02,0x40,0x00,0x00 };
const UBYTE e2[] = {0x00,0x01,0x05,0x09,0x0d,0x11};
const char *p[] = {"flat","jazz","pops",
"rock","crassic",NULL};
const char *c[] = { "EQ TYPE", "EQ GAIN1",
"EQ GAIN2","EQ GAIN3",
"EQ GAIN4","EQ GAIN5"};
DWORD para;
if (!j) {
zms = getnum4(zms,¶,&err, p, 0);
} else {
zms = getnum2(zms,¶,&err);
}
if (*zms == ',') {
zms++;
}
e[2] = dev;
e[6] = e2[j];
e[7] = para;
*trkdata[0].zmd++ = 0x34;
*trkdata[0].zmd++ = ifno; /* IF number: (-1 == current IF) */
*trkdata[0].zmd++ = strlen(c[j]); /* comment length */
strcpy(trkdata[0].zmd, c[j]);
trkdata[0].zmd += strlen(c[j]);
putDword(trkdata[0].zmd, elen + 1); /* +2: checksum,0xf7 */
trkdata[0].zmd += 4;
trkdata[0].zmd = setex(trkdata[0].zmd, e, elen, 0);
*trkdata[0].zmd++ = 0xf7;
}
zms = skipSpc(zms);
if (*zms == '}') {
zms++;
}
cominf->z_cmn_flag |= (1 << (0x34 / 4));
if (cmnt) {
efree(cmnt,"cmnt");
}
}
break;
/*OK*/ case ZMSCMD_COMMENT:
{
int cmntflg = 0;
cominf->z_cmn_flag |= (1 << (0x34 / 4));
*trkdata[0].zmd++ = 0x40;
zms = skipSpc(zms);
if (*zms == '{') {
cmntflg = 1;
zms++;
}
cominf->cmnt = trkdata[0].zmd - trkdata[0].zmdbuf;
do {
while (*zms != 0x0a && (!cmntflg || *zms != '}')) {
*trkdata[0].zmd++ = *zms++;
}
if (!cmntflg) {
*trkdata[0].zmd++ = *zms++;
}
#ifdef A /* CR doesn't cut off on V3 */
if (*(zms - 2) == 0x0d) {
trkdata[0].zmd -= 2;
} else if (!cmntflg) {
trkdata[0].zmd -= 1;
}
#endif
line++;
ld = incrementLine(ld);
} while (cmntflg && *zms != '}');
*trkdata[0].zmd++ = 0; /* string end code */
if (*zms == '}') {
zms++;
}
/* printf("TITLE:%s\n",cominf->cmnt + trkdata[0].zmdbuf); */
}
break;
case ZMSCMD_MIDI_DATA:
/*OK*/ case ZMSCMD_EXCLUSIVE:
{
const UBYTE f0f7 = (i == ZMSCMD_MIDI_DATA)? 0 : 1;
const UBYTE roland = 0;
DWORD zmsskip;
DWORD ifno = -1;
char *cmnt;
zms = getIfnoAndComment(zms, "{",&ifno, &cmnt);
trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,
f0f7, &zmsskip,
ifno, cmnt,
roland,0,0,
0,"",
"{","}, \t\x0d\x0a");
cominf->z_cmn_flag |= (1 << (0x34 / 4));
zms += zmsskip;
if (cmnt) {
efree(cmnt,"cmnt");
}
}
break;
/*OK*/ case ZMSCMD_ROLAND_EXCLUSIVE:
{
const UBYTE f0f7 = 1,roland = 1;
DWORD dev,mdl,ifno = -1;
int err;
DWORD zmsskip;
char *cmnt = NULL;
zms = getnum2(zms,&dev,&err);
if (err < 0) {
dev = 0x10;
mdl = 0x16; /* default:MT-32? */
}
if (strchr(", \t",*zms)) {
zms = skipchr(zms,", \t\x0d\x0a");
zms = getnum2(zms,&mdl,&err);
#ifdef AAA
if (err < 0) {
mdl = 0x16; /* default:MT-32? */
}
#endif
}
zms = getIfnoAndComment(zms, "{", &ifno, &cmnt);
trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,
f0f7, &zmsskip,
ifno,cmnt,
roland,dev,mdl,
0,"",
"{","}, \t\x0d\x0a");
cominf->z_cmn_flag |= (1 << (0x34 / 4));
zms += zmsskip;
if (cmnt) {
efree(cmnt,"cmnt");
}
}
break;
case ZMSCMD_SC55_INIT:
case ZMSCMD_SC55_RESET:
case ZMSCMD_GS_INIT:
/*OK*/ case ZMSCMD_GS_RESET:
/* 18 00 0b f0 41 10 42 12 40 00 7f 00 41 ff */
{
const DWORD elen = 9;
BYTE e[9] = { 0xf0,0x41,0x10,0x42,0x12,0x40,0x00,0x7f,0x00 };
const int rolandchecksum = 1;
const int idflag = 1;
const BYTE target[] = {0, -1};
zms = macroExclusive0(zms, e, elen,
"GS_RESET",
idflag,
rolandchecksum, trkdata, target);
}
break;
/*OK*/ case ZMSCMD_GM_SYSTEM_ON:
/*OK*/ case ZMSCMD_GM2_SYSTEM_ON:
/* 18 00 06 F0 7E 7F 09 01 F7 */
{
const BYTE target[] = {0, -1};
if (i == ZMSCMD_GM_SYSTEM_ON) {
zms = makeZmdGmSystemOn(zms, trkdata, cominf,
target);
} else {
zms = makeZmdGm2SystemOn(zms, trkdata, cominf,
target);
}
#ifdef Aa
const DWORD elen = 5;
BYTE e[5] = { 0xf0,0x7e,0x7f,0x09,0x01 };
const int rolandchecksum = 0;
const int idflag = 0;
const BYTE target[] = {0, -1};
zms = macroExclusive0(zms, e, elen,
"GM_SYSTEM_ON",
idflag,rolandchecksum, trkdata, target);
#endif
}
break;
/*OK*/ case ZMSCMD_XG_SYSTEM_ON: /* zmc2 extention */
/*OK*/ case ZMSCMD_XG_INIT: /* zmc3 extention */
/* 18 00 09 F0 43 10 4C 00 00 7e 00 F7 */
{
const BYTE target[] = {0, -1};
zms = makeZmdXgSystemOn(zms, trkdata, cominf,
target);
#ifdef AA
const DWORD elen = 8;
BYTE e[8] = { 0xf0,0x43, 0x10, 0x4c,
0x00,0x00,0x7e,0x00 };
const int rolandchecksum = 0;
const int idflag = 1;
const BYTE target[] = {0,-1};
zms = macroExclusive0(zms, e, elen,
"XG_SYSTEM_ON",
idflag,rolandchecksum, trkdata, target);
zmserror(".xg_system_on can use only for zmc2.",line,linebuf,zms,4,1);
#endif
}
break;
case ZMSCMD_SC55_V_RESERVE:
case ZMSCMD_SC55_PARTIAL_RESERVE:
case ZMSCMD_GS_V_RESERVE:
case ZMSCMD_GS_PARTIAL_RESERVE:
case ZMSCMD_SC55_REVERB:
case ZMSCMD_GS_REVERB:
case ZMSCMD_SC55_CHORUS:
case ZMSCMD_GS_CHORUS:
case ZMSCMD_SC88_REVERB:
case ZMSCMD_SC88_CHORUS:
/*OK*/ case ZMSCMD_SC88_DELAY:
/* 41 10 42 12 40 01 10 01 ... */
{
DWORD dev, ifno = -1;
int err;
const int f0f7 = 1,roland = 1;
const UBYTE mdl = 0x42;
DWORD zmsskip;
const int zmdlen[4] = { 29, 20+13, 21+13, 23+12 };
BYTE e[4][3] = { 0x40,0x01,0x10, /* v_reserve */
0x40,0x01,0x30, /* reverb */
0x40,0x01,0x38, /* chorus */
0x40,0x01,0x50 }; /* 88delay */
int cmd, sc88 = 0;
UBYTE *zmd_ = trkdata[0].zmd;
char *cmnt[] = {
"GS_PARTIAL_RESERVE",
"GS_REVERB",
"GS_CHORUS",
"",
"SC88_REVERB",
"SC88_CHORUS",
"SC88_DELAY"
};
if (i == ZMSCMD_SC55_V_RESERVE ||
i == ZMSCMD_SC55_PARTIAL_RESERVE ||
i == ZMSCMD_GS_V_RESERVE ||
i == ZMSCMD_GS_PARTIAL_RESERVE) {
cmd = 0 ;
} else if (i == ZMSCMD_SC55_REVERB ||
i == ZMSCMD_GS_REVERB ||
i == ZMSCMD_SC88_REVERB) {
cmd = 1 ;
} else if (i == ZMSCMD_SC55_CHORUS ||
i == ZMSCMD_GS_CHORUS ||
i == ZMSCMD_SC88_CHORUS) {
cmd = 2 ;
} else {
cmd = 3 ;
}
if (i == ZMSCMD_SC88_REVERB ||
i == ZMSCMD_SC88_CHORUS ||
i == ZMSCMD_SC88_DELAY) {
sc88 = 1 + 2; /* GS -> SC88 : +2 */
}
zms = getnum2(zms,&dev,&err);
if (err < 0) {
dev = 0x10;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (dev < 0) {
/* It is not to be error in V2 */
}
zms = skipSpc(zms);
if (*zms == ',') {
zms = getnum2(++zms, &ifno,&err);
if (err < 0) {
ifno = -1;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (ifno < 0) {
/* It is not to be error in V2 */
}
}
trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,
f0f7, &zmsskip,
ifno,
cmnt[cmd + (sc88? 3:0)],
roland,dev,mdl,
3,e[cmd],
"{","}, \t\x0d\x0a");
zms += zmsskip;
cominf->z_cmn_flag |= (1 << (0x34 / 4));
if (trkdata[0].zmd - zmd_ != zmdlen[cmd] + sc88 && /* non FULL parameters */
(trkdata[0].zmd - zmd_ != (18 + (int)strlen(cmnt[cmd + sc88])) && cmd != 0) ) {
/* non SINGLE parameter & non vreserve */
const char *warn[7] = {
".sc55_v_reserve must have just 16 parameters.",
".sc55_reverb must have 1 or 7 parameter(s).",
".sc55_chorus must have 1 or 8 parameter(s).",
"",
".sc88_reverb must have 1 or 8 parameter(s).",
".sc88_chorus must have 1 or 9 parameter(s).",
".sc88_delay must have 1 or 11 parameter(s)."
};
/*fprintf(stderr,"[%d]",trkdata[0].zmd - zmd_);*/
zmserror(warn[cmd + sc88],line,linebuf,zms,3,1);
}
if (cmd == 0) {
int i, sum = 0;
UBYTE tmp = *(zmd_ + 42);
memmove(zmd_ + 34, zmd_ + 33, 9); /* reorder */
*(zmd_ + 33) = tmp;
zmd_ = zmd_ + 33;
for (i = 0; i < 16; i++) {
sum += *zmd_++;
}
if (sum > 24) {
zmserror("voices should be less than or equal to 24 in voice-reserve.",line,linebuf,zms,3,1);
}
}
}
break;
/*OK*/ case ZMSCMD_SC88_EQUALIZER:
{
const DWORD elen = 3;
BYTE e[3] = { 0x40,0x02,0x00 };
const int roland = 1, idflag = 1, zmdlen = 17 + 18, mdl = 0x42;
const int warnlvl = 3;
zms = macroExclusiveN(zms, e, elen, zmdlen,
"SC88_EQUALIZER",
idflag,roland, mdl,warnlvl,
".sc88_equalizer must have just 4 parameters.",
trkdata);
/* zmserror(".sc88_equalizer can use only on V3.",line,linebuf,zms,3,1); */
cominf->z_cmn_flag |= (1 << (0x34 / 4));
}
break;
case ZMSCMD_SC55_PART_SETUP:
case ZMSCMD_SC55_PART_PARAMETER:
case ZMSCMD_GS_PART_SETUP:
case ZMSCMD_GS_PART_PARAMETER:
case ZMSCMD_SC88_PART_SETUP:
/*OK*/ case ZMSCMD_SC88_PART_PARAMETER:
{
const UBYTE f0f7 = 1,roland = 1;
const UBYTE mdl= 0x42;
DWORD dev, ifno;
int err;
DWORD zmsskip,part;
const DWORD elen = 3;
BYTE e[3] = { 0x40,0x10,0x02 };
int cmd = (i == ZMSCMD_SC88_PART_SETUP ||
i == ZMSCMD_SC88_PART_PARAMETER)?
1 : 0;
int paras = (cmd == 1)? 127 : 119;
UBYTE *zmd_ = trkdata[0].zmd;
char *cmnt[] = {"GS_PART_SETUP","SC88_PART_SETUP"};
zms = getnum2(zms,&part,&err);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
zms = getnum2(zms,&dev,&err);
if (err == -1) {
dev = 0x10;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (dev < 0) {
/* It is not to be error in V2, but.... */
}
if (part == 10) {
part = 0;
} else if (part > 10) {
part--;
}
e[2] = 0x10 + part;
zms = skipSpc(zms);
if (*zms == ',') {
zms = getnum2(++zms, &ifno,&err);
if (err < 0) {
ifno = -1;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (ifno < 0) {
/* It is not to be error in V2 */
}
}
trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,
f0f7, &zmsskip,
ifno,cmnt[cmd],
roland,dev,mdl,
elen,e,
"{","}, \t\x0d\x0a");
#ifdef AAA
if (trkdata[0].zmd - zmd_ > 13 + paras) { /* non FULL parameters */
/* 18 ll ll f0 41 10 42 12 40 1x 02 n1 n2 ... x127 sum f7 */
if (paras == 119) {
zmserror(".sc55_part_setup: too many parameters.",line,linebuf,zms,2,1);
} else {
zmserror(".sc88_part_setup: too many parameters.",line,linebuf,zms,3,1);
}
}
#endif
zms += zmsskip;
cominf->z_cmn_flag |= (1 << (0x34 / 4));
}
break;
case ZMSCMD_SC55_DRUM_SETUP:
case ZMSCMD_GS_DRUM_SETUP:
case ZMSCMD_SC88_DRUM_SETUP:
{
DWORD map,key,id,ifno = -1;
int j,err;
const int elen = 9;
BYTE e[9] = { 0xf0,0x41,0x10,0x42,0x12,0x41,0x00,0x00,0x00 };
int paras = (i == ZMSCMD_SC88_DRUM_SETUP)? 9 : 8;
zms = getnum2(zms,&map,&err);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
zms = skipchr(zms,", \t\x0d\x0a");
zms = getnum2(zms,&key,&err);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
zms = skipchr(zms,", \t\x0d\x0a");
zms = getnum2(zms,&id,&err);
if (err == -1) {
id = 0x10;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (id < 0) {
/* It is not to be error in V2, but.... */
}
e[2] = id;
zms = skipSpc(zms);
if (*zms == ',') {
zms = getnum2(++zms, &ifno,&err);
if (err < 0) {
ifno = -1;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (ifno < 0) {
/* It is not to be error in V2 */
}
}
*trkdata[0].zmd++ = 0x34;
*trkdata[0].zmd++ = ifno;
*trkdata[0].zmd++ = 0; /* comment */
putDword(trkdata[0].zmd, (elen + 2) * paras); /* +2: checksum,0xf7 */
trkdata[0].zmd += 4;
zms = skiptochr(zms,"{");
zms++;
for (j = 0; j < paras; j++) {
DWORD var;
zms = getnum2(zms,&var,&err);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
/* e[0] = 0x41; */
e[6] = (map << 4) + (j + 1);
e[7] = key;
e[8] = var;
trkdata[0].zmd = setex(trkdata[0].zmd, e, elen, 1);
*trkdata[0].zmd++ = 0xf7;
zms = skipchr(zms,", \t\x0d\x0a");
}
zms = skiptochr(zms,"}");
zms++;
cominf->z_cmn_flag |= (1 << (0x34 / 4));
}
break;
case ZMSCMD_SC55_PRINT:
case ZMSCMD_GS_PRINT:
{
DWORD dev, ifno = -1;
int err;
const int f0f7 = 1,roland = 1;
const UBYTE mdl = 0x45;
int elen = 3;
UBYTE e[3] = {0x10,0x00,0x00};
DWORD zmsskip;
zms = getnum2(zms,&dev,&err);
if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (err < 0) {
dev = 0x10;
}
zms = skipSpc(zms);
if (*zms == ',') {
zms = getnum2(++zms, &ifno,&err);
if (err < 0) {
ifno = -1;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (ifno < 0) {
/* It is not to be error in V2 */
}
}
trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,
f0f7, &zmsskip,
ifno, "GS_PRINT",
roland,dev,mdl,
elen,e,
"\"","\"\x0d\x0a");
/*
if (trkdata[0].zmd - ex_b0 > 3+5+3+32+1) {
zmserror("it must be under 32 characters in .sc55_print.",line,linebuf,zms,2,1);
}
*/
zms += zmsskip;
cominf->z_cmn_flag |= (1 << (0x34 / 4));
}
break;
case ZMSCMD_XG_PRINT:
{
const BYTE target[] = { 0, -1 };
zms = makeZmdXgPrint(zms, trkdata, target);
}
break;
case ZMSCMD_SC55_DISPLAY:
case ZMSCMD_GS_DISPLAY:
{
const BYTE target[] = { 0, -1 };
zms = makeZmdGsXgDisplay(zms, trkdata, cominf, target, 0);
}
break;
case ZMSCMD_XG_DISPLAY: /* zmc3 extention */
{
const BYTE target[] = { 0, -1 };
zms = makeZmdGsXgDisplay(zms, trkdata, cominf, target, 1);
}
break;
case ZMSCMD_WAVE_FORM:
/* 0x4a, size(.w), no(.b).looptype(.b),looppoint(.w),data(.w),.. */
{
DWORD waveno,looptype = 0,ls = 0,num = 0;
DWORD le = -1, lt = 0;
char *cmnt = NULL;
UBYTE *ws = trkdata[0].zmd + 3;
int err;
zms = getnum2(zms,&waveno,&err);
if (err) {
zmserror("wave# is not specified.",line,linebuf,zms,0,1);
}
zms = skipSpcCr(zms);
if (*zms == ',') {
zms++;
}
{
const char *p[] = {"1shot", "repeat", "alternate",NULL};
zms = getnum4(zms,&looptype,&err, p, 0);
if (err) {
zmserror("looptype is not specified.",line,linebuf,zms,0,1);
}
}
zms = skipSpcCr(zms);
if (*zms == ',') {
zms++;
}
{
zms = getnum2(zms,&ls,&err);
/*
if (err) {
zmserror("looppoint is not specified.",line,linebuf,zms,2,1);
}
*/
}
zms = skipSpcCr(zms);
if (*zms == ',') {
zms++;
}
{
zms = getnum2(zms,&le,&err);
if (err < 0) {
le = -1;
}
/*
if (err) {
zmserror("looppoint is not specified.",line,linebuf,zms,2,1);
}
*/
}
zms = getIfnoAndComment(zms, "{", <, &cmnt);
if (lt < 0) {
lt = 0;
}
cominf->z_cmn_flag |= (1 << (0x1c / 4));
*trkdata[0].zmd++ = 0x1c;
putWord(trkdata[0].zmd, waveno);
trkdata[0].zmd += 2;
trkdata[0].zmd += 4; /* size will be set */
*trkdata[0].zmd++ = looptype;
putDword(trkdata[0].zmd,ls * 2);
trkdata[0].zmd += 4;
putDword(trkdata[0].zmd,le * 2 + 2);
trkdata[0].zmd += 4;
putDword(trkdata[0].zmd,lt);
trkdata[0].zmd += 4;
putDword(trkdata[0].zmd,0);
trkdata[0].zmd += 4;
if (cmnt) {
*trkdata[0].zmd++ = strlen(cmnt);
strcpy(trkdata[0].zmd, cmnt);
trkdata[0].zmd += strlen(cmnt);
} else {
*trkdata[0].zmd++ = 0;
}
if ((trkdata[0].zmd - trkdata[0].zmdbuf) & 1) {
*trkdata[0].zmd++ = 0;
}
zms--;
do {
zms = skipSpcCr(zms + 1);
} while (*zms == '=');
if (*zms != '{') {
zmserror("wave definition error.",line,linebuf,zms,0,1);
}
zms++;
while (*zms != '}') { /* Too weak the error check is! */
DWORD tmpDWORD;
zms = getnum2(zms,&tmpDWORD,&err);
if (!err) {
putWord(trkdata[0].zmd, tmpDWORD);
trkdata[0].zmd += 2;
num++;
}
zms = skipSpcCr(zms);
if (*zms == ',') {
zms++;
} else if (*zms == '/') {
zms = skipComment(zms);
}
}
zms++;
putDword(ws,num * 2);
if (le < 0) {
putDword(ws + 9, num * 2);
}
if (cmnt) {
efree(cmnt,"cmnt");
}
}
break;
case ZMSCMD_RANDOMIZE_SEED: /* zmc2 extention */
{
DWORD seed;
int err;
zms = skipSpcCr(zms);
zms = getnum2(zms,&seed,&err);
if (err) {
srand(time(NULL));
/* zmserror("random_seed error.",line,linebuf,zms,0,1); */
} else {
srand(seed);
}
zmserror(".randomize_seed can use only for zmc2.",line,linebuf,zms,4,1);
}
break;
case ZMSCMD_LEGACY_1CLOCK_TIE: /* zmc2 extention */
{
DWORD tie;
int err;
zms = getnum2(zms,&tie,&err);
if (err) {
cominf->l1tie = 1;
} else {
cominf->l1tie = tie;
}
zmserror(".legacy_*1_tie can use only for zmc2.",line,linebuf,zms,4,1);
};
break;
case ZMSCMD_DEFINE: /* V3 extention */
{
int bnest = 0;
while (*zms != 0xFF) {
if (*zms == '{') {
bnest++;
} else if (*zms == '}') {
bnest--;
if (bnest <= 0) {
zms++;
break;
}
} /* macro expansion is already done */
zms++;
}
}
/*
zmserror(".define can use only on V3.",line,linebuf,zms,3,1);
*/
break;
case ZMSCMD_LENGTH_MODE: /* V3 extention */
zms = skipLine(zms);
break;
case ZMSCMD_TRACK: /* V3 extention */
zms = makeZmdPlaytrk(zms, trkdata, &stat, &playtrk_start, 0);
#ifdef A
stat = 1;
*trkdata[0].zmd++ = 0xFF;
if ((trkdata[0].zmd - trkdata[0].zmdbuf) & 1) {
*trkdata[0].zmd++ = 0xFF;
}
while ( *zms != '.' ) { /* '('まで戻す */
zms--;
}
if (!playtrk_start) {
playtrk_start = zms;
}
/* zms = skipLine(zms); */ /* del v0.71 */
#endif
break;
/* (BEGIN FM/ADPCMsupport by Mamiya */
#ifdef AAA
case ZMSCMD_MIDI_DUMP:
case ZMSCMD_ADPCM_BLOCK_DATA:
case ZMSCMD_ADPCM_LIST:
{
UBYTE *strstart;
BYTE cr;
int len;
if (i == ZMSCMD_MIDI_DUMP) {
*trkdata[0].zmd++ = 0x62;
} else if (i == ZMSCMD_ADPCM_BLOCK_DATA) {
*trkdata[0].zmd++ = 0x63;
} else if (i == ZMSCMD_ADPCM_LIST) {
*trkdata[0].zmd++ = 0x60;
}
zms = skipSpc(zms);
if (*zms == '=') zms = skipSpc(zms + 1);
strstart = zms;
zms = skipComment(zms);
if (*(zms - 1) == 0x0a && *(zms - 2) == 0x0d) {
cr = 2;
} else {
cr = 1;
}
len = zms - cr - strstart;
if (getSwitchVal('z') > 1) {
int i;
UBYTE c = 0;
for (i = 0; i < len; i++) {
if (c & 0x80)
c = strstart[i];
else if (isalpha(strstart[i]))
c = toupper(strstart[i]);
else if (strstart[i] <= ' ')
break;
else
c = strstart[i];
*trkdata[0].zmd++ = c;
}
} else {
strncpy(trkdata[0].zmd, strstart, len);
trkdata[0].zmd += len;
}
*trkdata[0].zmd++ = 0;
}
break;
case ZMSCMD_FM_VSET:
{
DWORD dat;
int err, i;
zms = skipSpcCr(getnum2(zms,&dat,&err));
if (*zms == '=') zms = skipSpcCr(zms + 1);
if (err < 0 || *zms != '{') {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
zms++;
memcpy(cominf->opmtone + 55 - 9, default_fmtone + 55 - 9, 9);
*trkdata[0].zmd++ = 0x1B;
*trkdata[0].zmd++ = dat;
for (i = 0 ; i < 55 ; i++) {
zms = skipchr(zms," ,\t");
zms = getnum2(zms,&dat,&err);
if (err < 0) break;
cominf->opmtone[i] = dat;
}
memcpy(trkdata[0].zmd, cominf->opmtone, 55);
trkdata[0].zmd += 55;
zms = skipSpcCr(zms);
if (*zms != '}') {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
zms++;
}
break;
case ZMSCMD_ADPCM_BANK:
{
DWORD v;
int err;
zms = skipSpc(zms);
if (*zms == '=') zms = skipSpc(zms + 1);
zms = getnum2(zms, &v, &err);
if (err) {
zmserror("adpcm_bank must be followed to its parameter.",line,linebuf,zms,0,1);
} else if (v < 1 || 4 < v) {
zmserror("adpcm_bank parameter is out of range(1-4).",line,linebuf,zms,0,1);
} else {
cominf->adpcmbank = v - 1;
}
}
break;
case ZMSCMD_FM_MASTER_VOLUME:
{
DWORD v;
int err;
zms = skipSpc(zms);
if (*zms == '=') zms = skipSpc(zms + 1);
zms = getnum2(zms, &v, &err);
if (err) {
zmserror("fm_master_volume must be followed to its parameter.",line,linebuf,zms,0,1);
} else if (v < 0 || 255 < v) {
zmserror("fm_master_volume parameter is out of range(0-255).",line,linebuf,zms,0,1);
} else {
cominf->fmvol = v;
}
}
break;
case ZMSCMD_ERASE:
{
DWORD v;
int err;
zms = skipSpc(zms);
if (*zms == '.') zms = skipSpc(zms + 1);
if (*zms == 'o' || *zms == 'O') {
UBYTE note;
zms = skipSpc(getnum2(zms + 1, &v, &err));
note = *zms | 0x20;
if (note < 'a' || 'g' < note) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
do {
zms = skipSpc(zms + 1);
} while (*zms == '+' || *zms == '#' || *zms == '-');
} else {
zms = getnum2(zms, &v, &err);
}
}
break;
case ZMSCMD_O:
{
const BYTE ntbl[] = {9,11,0,2,4,5,7};
DWORD oct;
UBYTE note;
int err;
zms = skipSpc(getnum2(zms, &oct, &err));
if (err) oct = 0;
note = *zms | 0x20;
if (note < 'a' || 'g' < note) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
zms = skipSpc(zms + 1);
note = 12 * (1 + oct) + ntbl[note - 'a'];
while (*zms == '+' || *zms == '#' || *zms == '-') {
note += (*zms == '-') ? -1 : 1;
zms = skipSpc(zms + 1);
}
zms = makeZmdCommonRegPcm(zms, trkdata, note, cominf->adpcmbank);
}
break;
#endif
/* FM/ADPCMsupport by Mamiya END) */
}
break;
case '(':
{
char c;
zms = skipSpc(zms);
c = *zms++;
switch(c) {
/*OK*/ case 'i': case 'I': /* (i) */
zms = initializeZMD(zms, trkdata, ")");
cominf->z_cmn_flag |= (1 << (0x00 / 4));
break;
case 'x': case 'X': /* (X...) */
{
const UBYTE f0f7 = 0,roland = 0;
DWORD zmsskip;
DWORD ifno = -1; /*cominf->currentmidiout;*/
char *cmnt = NULL;
trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,f0f7,&zmsskip,
ifno,cmnt,
roland,0,0,0,"","","), \t\x0d\x0a");
zms += zmsskip;
cominf->z_cmn_flag |= (1 << (0x34 / 4));
}
break;
case 'm': case 'M': /* (M1,1000) */
/* no need to support */
{
DWORD trk, bufsize;
int err;
/* zms = skipSpc(zms); */
zms = getnum2(zms, &trk, &err);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
zms = skipchr(zms,", \t");
zms = getnum2(zms, &bufsize,&err);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
zms = skiptochr(zms,")");
zms++;
trkdata[trk].buforgsize = bufsize;
}
break;
case 'b': case 'B': /* (B0) (B1) */
/* no need to support?????? */
{
int err;
DWORD basech;
zms = getnum2(zms,&basech,&err);
if (err || (basech != 0 && basech != 1)) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
cominf->basech = basech;
zms = skiptochr(zms,")");
zms++;
}
break;
/*OK*/ case 'a': case 'A': /*(Ach,tr) */
{
zms = makeZmdAssign(zms,trkdata,cominf,&trks,1);
#ifdef A
DWORD trk, ch, chtype;
int i,err;
zms = getDevice(zms,&ch, &chtype, cominf, 0);
zms = skipchr(zms," ,\t");
zms = getnum2(zms,&trk,&err);
if (err) {
zmserror("no track number is specified.",line,linebuf,zms,0,1);
} else if (trk <= 0) {
zmserror("illegal track number is specified.",line,linebuf,zms,0,1);
}
for (i = 0; i < trks; i++) {
if (cominf->trkassign[i] == trk) {
zmserror("The specified track# is already used.",line,linebuf,zms,0,1);
}
}
trkdata[trk].ch = trkdata[trk].ch_ = ch;
trkdata[trk].chtype = chtype;
cominf->trkassign[trks++] = trk;
cominf->trkassign[trks] = -1;
zms = getAssign2(zms, trkdata, trk, ")");
/* fprintf(stderr,"[%d,%d]",trk,ch); */
#endif
}
break;
case 't': case 'T': /* (T...) */
zms = makeZmdPlaytrk(zms,trkdata,&stat,&playtrk_start,1);
#ifdef A
stat = 1;
*trkdata[0].zmd++ = 0xFF;
if ((trkdata[0].zmd - trkdata[0].zmdbuf) & 1) {
*trkdata[0].zmd++ = 0xFF;
}
while ( *zms != '(' ) { /* '('まで戻す */
zms--;
}
if (!playtrk_start) {
playtrk_start = zms;
}
/*zms = skipLine(zms);*/ /* del v0.71 */
#endif
break;
/*OK*/ case 'z': case 'Z':
zms = setMasterClock(zms, ")",cominf);
break;
/*OK*/ case 'o': case 'O': /* set tempo */
zms = setTempo(zms, ")",cominf);
break;
/*OK*/ case 'd': case 'D':
{
int err;
DWORD dbg;
zms = getnum2(zms,&dbg,&err);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
cominf->debug = dbg;
zms = skiptochr(zms,")");
zms++;
}
break;
case 'f': case 'F':
case 'p': case 'P':
case 's': case 'S':
case 'c': case 'C':
case 'e': case 'E':
case 'q': case 'Q':
case 'r': case 'R':
/* ignore: (Fn) (Pn1,n2,..) (Sn1,n2,...) (Cn1,n2,...) (Ech1,ch2,...) (Q) (R) */
zms = skiptochr(zms,")");
zms++;
break;
/* (BEGIN FM/ADPCMsupport by Mamiya */
case 'v': case 'V':
{
DWORD dat;
int err, i;
zms = getnum2(zms,&dat,&err);
if (err < 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
*trkdata[0].zmd++ = 0x04;
*trkdata[0].zmd++ = dat;
zms = skipchr(zms," ,\t");
zms = getnum2(zms,&dat,&err);
if (err < 0 || dat != 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
for (i = 0 ; i < 55 ; i++) {
zms = skipchr(zms," ,\t");
zms = getnum2(zms,&dat,&err);
if (err < 0) break;
cominf->opmtone[i] = dat;
}
memcpy(trkdata[0].zmd, cominf->opmtone, 55);
trkdata[0].zmd += 55;
zms = skipSpcCr(zms);
if (*zms != ')') {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
zms++;
}
break;
case '@':
{
DWORD dat;
int err, i;
zms = getnum2(zms,&dat,&err);
if (err < 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
memcpy(cominf->opmtone + 55 - 9, default_fmtone + 55 - 9, 9);
*trkdata[0].zmd++ = 0x1B;
*trkdata[0].zmd++ = dat;
for (i = 0 ; i < 55 ; i++) {
zms = skipchr(zms," ,\t");
zms = getnum2(zms,&dat,&err);
if (err < 0) break;
cominf->opmtone[i] = dat;
}
memcpy(trkdata[0].zmd, cominf->opmtone, 55);
trkdata[0].zmd += 55;
zms = skipSpcCr(zms);
if (*zms != ')') {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
zms++;
}
break;
/* FM/ADPCMsupport by Mamiya END) */
default:
zmserror("UNKNOWN MML",line,linebuf,zms,0,1);
}
}
break;
default:
if (!playtrk_start && !mode) {
zms--;
if (*zms != ' ' && *zms != '\t' && *zms != 0x0d && *zms != 0x0a && *zms != 0x1A) {
/*
fprintf(stderr,"ERR! %.2X (%c)\n",*zms,*zms);
*/
/* omitted (AMIDI1,1)(T1) */
makeZmdAssignMain(trkdata,cominf,1,&trks,0,0x8000);
stat = 1;
/* zmserror("SYNTAX ERROR",line,linebuf,zms,0,1); */
} else {
zms++;
}
} else {
/*fprintf(stderr,"[.1(%x)]",*(zms - 1));*/
if (*(zms - 1) != 0x1A) {
/*fprintf(stderr,"[!]");*/
zmserror("unknown MML.",line,linebuf,zms,2,1);
zms = skipLine(zms);
} else {
/* zms = skipLine(zms);
zmserror("dummy warning.",line,linebuf,zms,2,1);
*/
}
}
break;
}
/*
if (stat) {
break;
}
*/
/*fprintf(stderr,"(loopend)\n");*/
}
*zms2 = (playtrk_start)? playtrk_start : zms;
trkdata[0].nowsize = (trkdata[0].zmdbuf[0] == 0xFF)? /* no common data? */
0 : trkdata[0].zmd - trkdata[0].zmdbuf;
return trkdata;
}
/* ===========================================
exclusive w/o any parameters(except ID,ifno)
=========================================== */
UBYTE *macroExclusive0(UBYTE *zms, BYTE e[], const DWORD elen,
const char *cmnt,
int idflag, int roland, TRKCHINF *trkdata,
const BYTE target[])
{
int err = 0;
DWORD ID, ifno = 0xFF;
UBYTE *zms_ = zms;
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
int err;
int Trk = target[trk];
if (idflag) {
zms = getnum2(zms,&ID,&err);
if (err == -1) {
ID = 0x10;
} else if (err > 0) {
zmserror("exclusive ID error.",line,linebuf,zms,0,1);
} else if (ID < 0) {
/* It is not to be error in V2, but.... */
}
e[2] = ID;
zms = skipSpc(zms);
if (*zms == ',') {
zms++;
}
}
zms = getnum2(zms,&ifno,&err);
if (err == -1) {
ifno = 0xFF;
} else if (err > 0) {
zmserror("IF number error.",line,linebuf,zms,0,1);
} else if (ID < 0) {
/* It is not to be error in V2, but.... */
} else {
ifno--; /* 1-4 -> 0-3 */
}
if (Trk) {
*trkdata[Trk].zmd++ = 0xf4;
} else {
*trkdata[0].zmd++ = 0x34;
*trkdata[0].zmd++ = ifno; /* IF number: (-1 == current IF) */
}
*trkdata[Trk].zmd++ = strlen(cmnt); /* comment length */
strcpy(trkdata[Trk].zmd, cmnt);
trkdata[Trk].zmd += strlen(cmnt);
putDword(trkdata[Trk].zmd, elen + (roland? 2 : 1)); /* +2: checksum,0xf7 */
trkdata[Trk].zmd += 4;
trkdata[Trk].zmd = setex(trkdata[Trk].zmd, e, elen, roland);
*trkdata[Trk].zmd++ = 0xf7;
}
return zms;
}
/* ===========================================
exclusive w/ many parameters(except ID)
ex_macro id {n1,n2,...}
sorry the usage has a little difference
from macroExclusive0
=========================================== */
UBYTE *macroExclusiveN(UBYTE *zms, BYTE e[], const DWORD elen,const DWORD zmdlen,
const char *cmnt,
int idflag, int roland, const UBYTE mdl,const int warnlvl,
UBYTE *warn, TRKCHINF *trkdata)
{
DWORD dev, ifno;
int err = 0;
const int f0f7 = 1;
DWORD zmsskip;
UBYTE *zmd_ = trkdata[0].zmd;
if (idflag) {
zms = getnum2(zms,&dev,&err);
if (err == -1) {
dev = 0x10;
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (dev < 0) {
/* It is not to be error in V2 */
}
zms = skipSpc(zms);
if (*zms == ',') {
zms++;
}
}
zms = getnum2(zms,&ifno,&err);
if (err == -1) {
ifno = 0xFF;
} else if (err > 0) {
zmserror("IF number error.",line,linebuf,zms,0,1);
} else if (err < 0) {
/* It is not to be error in V2, but.... */
}
trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,
f0f7, &zmsskip,ifno, cmnt, roland,dev,mdl,
elen,e,
"{","}, \t\x0d\x0a");
zms += zmsskip;
if (trkdata[0].zmd - zmd_ != zmdlen) { /* non FULL parameters */
zmserror(warn,line,linebuf,zms,warnlvl,1);
}
return zms;
}
UBYTE *getDevice(UBYTE *zms, DWORD *ch, DWORD *chtype, COMMONINF *cominf,
int allowALL)
{
int err;
zms = getnum2(zms,ch,&err);
if (err > 0) {
zmserror("illegal channel number is specified.",line,linebuf,zms,0,1);
} else if (err < 0) { /* (a????x,y) */
int i,flg = -1;
const char *base[4] = {"fm","adpcm","midi","all"};
const int bs[4] = {0,8,9,-1};
const int chtp[] = {0, 1, 0x8000, -2};
DWORD d, d2 = -1;
int b = 0, err, err2 = -1;
const int target = (allowALL)? 4 : 3;
for (i = 0; i < target; i++) {
if (!stricmp2(zms,base[i])) {
flg = i;
b = bs[flg];
*chtype = chtp[flg];
zms += strlen(base[i]);
break;
}
}
zms = getnum2(zms,&d,&err);
zms = skipSpc(zms);
if (*zms == '-') {
DWORD temp;
const char *p[] = {"all",NULL};
zms = getnum4(++zms,&d2,&err2,p, -1);
temp = d2; d2 = d; d = temp;
temp = err2; err2 = err; err = temp;
}
/* fprintf(stderr,"err=%d, err2=%d flg=%d\n",err,err2,flg); */
/* fprintf(stderr,"d=%d, d2=%d ",d,d2); */
if (err < 0) {
if (flg != 1 && flg != 3) { /* non (adpcm || all) && omit ch */
zmserror("illegal channel-strings is specified.",line,linebuf,zms,0,1);
} else {
/* (BEGIN FM/ADPCMsupport by Mamiya */
if (cominf->polpcm++) {
*ch = 25 + cominf->polpcm - 2;
} else {
/* FM/ADPCMsupport by Mamiya END) */
if (flg == 1) { /* adpcm */
*ch = 8;
} else if (flg == 3) { /* ALL */
*ch = -2;
}
}
}
} else if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
/* (BEGIN FM/ADPCMsupport by Mamiya */
} else if (flg == 1) { /* adpcm */
*ch = (d == 1) ? 8 : (25 + d - 2);
/* FM/ADPCMsupport by Mamiya END) */
} else if (flg == 3) { /* ALL */
*ch = -2;
} else { /*(AxxxxN,m)*/
if (err2 < 0) { /* (AxxxxN,M) */
/* fprintf(stderr,"chtype1 = %d",*chtype); */
/* *ch = d + b - 1; */
*ch = d - 1;
/* fprintf(stderr,"CH= %d",*ch); */
if (flg == 2) { /* (AMIDIn,m) */
*chtype = 0xFFFF; /* current midi out */
/* fprintf(stderr,"chtype2 = %d",*chtype); */
} else if (flg == 1) { /* (AADPCMx,y) */
if (*ch > 8) { /* ADPCM2-16 */
*ch += 16;
}
}
} else if (flg == 2) { /* (AMIDIx-y,z */
/* fprintf(stderr,"chtype3 = %d, ch=%d, d2=%d ",*chtype, d-1, d2); */
/* *ch = d + b - 1; */
*ch = d - 1;
if (*ch < 0 || 16 <= *ch) {
zmserror("illegal channel number is specified. (must be in between 1 to 16)",line,linebuf,zms,0,1);
}
/*
if (d2 > 1) {
*ch += (d2 - 1) * 16 + 15;
}
*/
*chtype += d2 - 1;
/* fprintf(stderr,"Ch= %d",*ch); */
}
}
} else { /* (ax,y) */
(*ch)--;
if (cominf->basech == 1) {
/* (BEGIN FM/ADPCMsupport by Mamiya */
if (*ch < 16) {
*ch += 9;
} else if (*ch < 16 + 9) {
*ch -= 16;
}
/* FM/ADPCMsupport by Mamiya END) */
}
if (*ch < 8) {
*chtype = 0; /* FM */
} else if (*ch == 8) { /* ADPCM1 */
*chtype = 1;
*ch = 0;
} else if (*ch < 25) { /* MIDI */
*chtype = 0xFFFF;
*ch -= 9;
} else if (*ch < 39) { /* ADPCM2-16 */
*chtype = 1;
*ch = (*ch - 9) % 16;
} else { /* MIDI */
*chtype = 0xFFFF;
}
}
/* fprintf(stderr,"[ch=%d chtype=%.4x]",*ch,*chtype); */
return zms;
}
UBYTE *setTempo(UBYTE *zms, char *endchar,COMMONINF *cominf)
{
int err;
DWORD tempo;
zms = getnum2(zms,&tempo,&err);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
cominf->tempo = tempo;
if (endchar) {
zms = skiptochr(zms,endchar);
zms++;
}
/*
*trkdata[0].zmd++ = 0x08;
putWord(trkdata[0].zmd,tempo);
trkdata[0].zmd += 2;
*/
return zms;
}
UBYTE *initializeZMD(UBYTE *zms, TRKCHINF *trkdata, const char *endchar)
{
int err;
DWORD num;
zms = getnum2(zms,&num,&err);
if (!err && num >= 3) {
zmserror("V3-zms is not supported in zmc2.",line,linebuf,zms,3,1);
}
zms = skipSpc(zms);
if (endchar && *zms++ != *endchar) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
*trkdata[0].zmd++ = 0x00;
*trkdata[0].zmd++ = num;
return zms;
}
UBYTE *setMasterClock(UBYTE *zms, const char *endchar,COMMONINF *cominf)
{
int err;
DWORD div;
zms = getnum2(zms,&div,&err);
if (err) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
cominf->div = div;
if (endchar) {
zms = skiptochr(zms,endchar);
zms++;
}
/* cominf->z_cmn_flag |= (1 << (0x0c / 4)); */
/*
*trkdata[0].zmd++ = 0x0c;
putWord(trkdata[0].zmd,div);
trkdata[0].zmd += 2;
*/
return zms;
}
UBYTE *getIfnoAndComment(UBYTE *zms, const char *endchar, DWORD *ifno, char **cmnt)
{
int err;
zms = skipSpc(zms);
if (*zms == '=') { /* legacy support */
*ifno = -1;
*cmnt = NULL;
zms = skipSpc(zms + 1);
} else if (*zms != ',') {
zms = getnum2(zms,ifno,&err);
if (err > 0) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
} else if (err < 0) {
*ifno = -1;
}
}
zms = skipSpc(zms);
if (*zms != ',') {
*cmnt = NULL;
} else {
UBYTE *zms_;
DWORD len;
zms_ = zms = skipSpc(zms + 1);
while (*zms != *endchar) {
zms++;
}
len = zms - zms_;
*cmnt = (char*)emalloc(sizeof(char) * (len + 1),"cmnt_in_getIfnoAndComment");
if (len) {
strncpy(*cmnt, zms_, len);
}
(*cmnt)[len] = '\0';
}
if (*zms != *endchar) {
zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
}
return zms;
}
UBYTE *getAssign2(UBYTE *zms, TRKCHINF *trkdata,const int trk, const char *endchar)
{
DWORD trkv = 128,trkf = 1,trks = 0,trkm = 0;
char *cmnt;
int err;
const char *trksstr[] = {"play", "record", NULL};
const char *trkmstr[] = {"normal", "rhythm", NULL};
trkdata[trk].trkv = trkv;
trkdata[trk].trkf = trkf;
trkdata[trk].trks = trks;
trkdata[trk].trkm = trkm;
trkdata[trk].cmnt = NULL;
zms = skipSpc(zms);
if (*zms == *endchar) {
zms++;
return zms;
} else if (*zms != ',') {
return zms;
/* zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1); */
} else {
zms = getnum2(++zms,&trkv,&err);
if (err && *zms != ',') {
zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1);
} else {
trkdata[trk].trkv = trkv;
}
}
zms = skipSpc(zms);
if (*zms == *endchar) {
zms++;
return zms;
} else if (*zms != ',') {
return zms;
/* zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1); */
} else {
zms = getnum2(++zms,&trkf,&err);
if (err && *zms != ',') {
zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1);
} else {
trkdata[trk].trkf = trkf;
}
}
zms = skipSpc(zms);
if (*zms == *endchar) {
zms++;
return zms;
} else if (*zms != ',') {
return zms;
/* zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1); */
} else {
zms = getnum4(++zms,&trks,&err,trksstr,0);
if (err && *zms != ',') {
zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1);
} else {
trkdata[trk].trks = trks;
}
}
zms = skipSpc(zms);
if (*zms == *endchar) {
zms++;
return zms;
} else if (*zms != ',') {
return zms;
/* zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1); */
} else {
zms = getnum4(++zms,&trkm,&err,trkmstr,0);
if (err && *zms != ',') {
zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1);
} else {
trkdata[trk].trkm = trkm;
}
}
zms = skipSpc(zms);
if (*zms == ',') {
UBYTE *zms__ = ++zms;
while (*zms != *endchar) {
zms++;
}
cmnt = (char*)emalloc(sizeof(char) * (zms - zms__ + 1),"cmnt_in_getAssign2");
if (zms - zms__) {
strncpy(cmnt,zms__,zms - zms__);
}
cmnt[zms - zms__] = '\0';
} else {
cmnt = NULL;
}
/*fprintf(stderr,"[%d: %s]",trk,cmnt); */
/*
if (*zms != *endchar) {
zmserror("`)' is unbraced.",line,linebuf,zms,0,1);
}
zms++;
*/
if (*zms == *endchar) {
zms++;
}
trkdata[trk].cmnt = cmnt;
/*
fprintf(stderr,"ASSIGN: trkv=%d trkf=%d trks=%d trkm=%d cmnt=%s\n",
trkv,trkf,trks,trkm,cmnt);
*/
return zms;
}
UBYTE *makeZmdAssign(UBYTE *zms,TRKCHINF *trkdata,
COMMONINF *cominf, BYTE *trks, const int mode)
{ /* mode: 0.. .assign 1.. (a) */
DWORD trk, ch, chtype;
int i, err;
const char *endchar[2] = { "}", ")" };
if (!mode) { /* .assign */
zms = skipSpc(zms);
if (!stricmp2(zms,"tr")) {
zms += 2;
}
} else { /* (A) */
zms = getDevice(zms,&ch, &chtype, cominf, 0);
zms = skipchr(zms," ,\t");
}
zms = getnum2(zms,&trk,&err);
if (err) {
zmserror("no track number is specified.",line,linebuf,zms,0,1);
} else if (trk <= 0) {
zmserror("illegal track number is specified. (must be over than 0)",line,linebuf,zms,0,1);
}
for (i = 0; i < *trks; i++) {
if (cominf->trkassign[i] == trk) {
zmserror("The specified track# is already used.",line,linebuf,zms,0,1);
}
}
if (!mode) {
zms = skipSpcCr(zms);
if (*zms == '{' || *zms == ',') {
zms++;
}
zms = getDevice(zms,&ch, &chtype, cominf, 0);
/*
zms = skiptochr(zms,"}");
zms++;
*/
}
makeZmdAssignMain(trkdata, cominf, trk, trks, ch, chtype);
/* fprintf(stderr,"[%d,%d]",trk,ch); */
zms = getAssign2(zms, trkdata, trk, endchar[mode]);
return zms;
}
void makeZmdAssignMain(TRKCHINF *trkdata,COMMONINF *cominf,
int trk, BYTE *trks, int ch, int chtype)
{
trkdata[trk].ch = trkdata[trk].ch_ = ch;
trkdata[trk].chtype = chtype;
cominf->trkassign[(*trks)++] = trk;
cominf->trkassign[*trks] = -1;
initTrkInf0(trkdata, trk);
/*fprintf(stderr,"[%d: %d,%d,%x]",*trks,trk,ch,chtype);*/
}
UBYTE *makeZmdPlaytrk(UBYTE *zms,TRKCHINF *trkdata,
int *stat, UBYTE **playtrk_start, int mode)
{
const char startchar[2] = { '.', '(' };
*stat = 1;
*trkdata[0].zmd++ = 0xFF;
if ((trkdata[0].zmd - trkdata[0].zmdbuf) & 1) {
*trkdata[0].zmd++ = 0xFF;
}
while ( *zms != startchar[mode] ) { /* '('まで戻す */
zms--;
}
if (!*playtrk_start) {
*playtrk_start = zms;
}
/* zms = skipLine(zms); */ /* del v0.71 */
return zms;
}